package com.group5.onlinegame.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.group5.onlinegame.entity.Demo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CommonService implements  ICommonService {
    /*公共方法*/


    /*先进页面在传值*/

    @Override
    public String getget(List<String> categories, List<Integer> data){
        Demo demo = new Demo();
        demo.setCategories(categories);
        demo.setData(data);
        ObjectMapper objectMapper = new ObjectMapper();
        String str = null;
        try {
            str = objectMapper.writeValueAsString(demo);
            System.out.println(str);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return str;
    }



    /*先获值在传页面*/
    @Override
    public Demo getget2(List<String> categories, List<Integer> data) {
        Demo demo=new Demo();
        List<String> c=new ArrayList<>();
        for (String s:categories){
            c.add ("'"+s+"'");
        }
        demo.setData(data);
        demo.setCategories(c);
        return demo;
    }
}
